package com.netx.ebs;
import com.netx.generics.basic.Checker;
import com.netx.generics.time.TimeValue;


public class AdministrationServlet extends AuthorizedServlet {

	protected AdministrationServlet(String permissionName) {
		super(new SecurityChecker[] {
			new AuthenticationChecker(),
			new AuthorizationChecker(permissionName)
		},
		permissionName);
	}

	protected void stopApplication(TimeValue startupTime) {
		Checker.checkNull(startupTime, "startupTime");
		final EbsContext ebsCtx = getEbsContext();
		if(ebsCtx.getApplicationState() == APPLICATION_STATE.STOPPED) {
			throw new IllegalStateException("applicaiton is already stopped");
		}
		else {
			ebsCtx.internalStopApplication();
			ebsCtx.internalSetStartupTime(startupTime);
		}
	}

	protected void startApplication() {
		final EbsContext ebsCtx = getEbsContext();
		if(ebsCtx.getApplicationState() == APPLICATION_STATE.RUNNING) {
			throw new IllegalStateException("applicaiton is already running");
		}
		else {
			ebsCtx.internalStartApplication();
		}
	}

	protected SessionManager getSessionManager() {
		return getEbsContext().internalGetSessionManager();
	}
}
